#!/bin/sh

JOBID=$1
USERNAME=$2
GROUPNAME=$3
JOBNAME=$4
REQLIMITS=$5
QUEUE=$6
JOBACCOUNT=$7

export `grep -a PBS_O_HOST jobs/$JOBID.JB`
nodefile=/var/spool/torque/aux/$JOBID

#tmfile=`mktemp`
#cp $nodefile $tmfile;
#cat $tmfile | sed -e 's/node-/node-ib-/g' > $nodefile 
#rm -f $tmpfile

if [ -r $nodefile ] ; then
    nodes=$(sort $nodefile | uniq)
else
    nodes=localhost
fi


for n in $nodes; do
    ssh $n "if [ ! -d /home/$USERNAME ]; then
        mkdir /home/$USERNAME;
fi;
N=\`grep $PBS_O_HOST:/home/$USERNAME /proc/mounts | wc -l\`;
if [ ! \$N -gt 0 ]; then
    mount $PBS_O_HOST:/home/$USERNAME /home/$USERNAME -t nfs;
fi"
done

exit 0
